package com.losdun.points.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.losdun.points.domain.PointsGoods;
import com.losdun.points.mapper.PointsGoodsMapper;
import com.losdun.points.service.PointsGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 积分商品表service实现类
 *
 * @author swordye
 * @date 2025-05-19
 */
@Slf4j
@Service
public class PointsGoodsServiceImpl extends ServiceImpl<PointsGoodsMapper, PointsGoods> implements PointsGoodsService {

    @Autowired
    private PointsGoodsMapper pointsGoodsMapper;


    @Override
    public List<PointsGoods> queryList(PointsGoods goods) {
        return baseMapper.selectList(new QueryWrapper<>(goods).orderByAsc("sort"));

    }


    @Override
    public boolean checkGoodsStock(String goodsId,Integer goodsNum) {
        PointsGoods entity = this.getById(goodsId);
        if(entity==null){
            throw new RuntimeException("兑换的商品不存在！");
        }
        if(entity.getStock()<goodsNum){
            throw new RuntimeException("兑换产品不足！");
        }
        return true;
    }
}
